package com.emep.changzhi.analyse.http.basics;

import com.emep.changzhi.analyse.entity.basics.SysAqiStandardDayInfo;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.basics.SysAqiStandardDayService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.Map;

/**
 * @author xy
 * @Description: aqi达标、污染天数控制器
 * @date 2018/3/23 11:11
 * @version V1.0
 */

@RestController
@RequestMapping("aqi/standard/day")
@Api(value = "aqi达标污染天数 controller",tags = "AQI达标污染天数控制器")
public class SysAqiStandardDayController {
    @Autowired
    private SysAqiStandardDayService sysAqiStandardDayService;

    /**
     * 查询当前年份所有api
     * @return
     */
    @ApiOperation(value="获取api达标污染天数列表(默认当前年份)", notes="无参数获取所有api达标污染天数信息(默认当前年份)")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @GetMapping(value = "list/year")
    public ResultBean<Collection<SysAqiStandardDayInfo>> queryUser(){
        return new ResultBean<Collection<SysAqiStandardDayInfo>>(sysAqiStandardDayService.list());
    }
    /**
     * 查询所有api
     * @return
     */
    @ApiOperation(value="获取api达标污染天数列表", notes="无参数获取所有api达标污染天数信息")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @GetMapping(value = "list")
    public ResultBean<Collection<SysAqiStandardDayInfo>> queryAll(){
        return new ResultBean<Collection<SysAqiStandardDayInfo>>(sysAqiStandardDayService.listAll());
    }

    /**
     * 新增api达标污染天数
     * @param payload
     * @return
     */
    @ApiOperation(value="新增api达标污染天数", notes="新增api达标污染天数")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "修改时传的id", required = false, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "year", value = "污染类型年份", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "excellentMax", value = "最大优天气", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "pollutionMax", value = "最大良天气", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "pm25Max", value = "最大污染天气", required = true, dataType = "String",paramType="query")
    })
    @PostMapping(value = "add")
    public ResultBean<SysAqiStandardDayInfo> add(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "year","excellentMax"
                ,"pollutionMax","pm25Max");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return result.boolAdd(sysAqiStandardDayService.save(payload)) ;
        }
        return  result;
    }
}
